//
//  TreeNextUI.m
//  mbstore
//
//  Created by Juvid on 14-4-16.
//  Copyright (c) 2014年 huangyi. All rights reserved.
//

#import "TreeNextUI.h"
#import "HomeUI.h"
@implementation TreeNextUI

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self SetNextView];
    }
    return self;
}
-(void)SetNextView{
    UIView *vieHead=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 44)];
    vieHead.backgroundColor=[UIColor colorWithRed:249.0/255.0 green:249.0/255.0 blue:249.0/255.0 alpha:1];
    [self addSubview:vieHead];
    UILabel *labSearchResult=[[UILabel alloc]initWithFrame:CGRectMake(20, 10, 500, 24)];
    labSearchResult.text=@"共搜到269件商品";
    labSearchResult.font=[UIFont systemFontOfSize:14];
    [vieHead addSubview:labSearchResult];
    
    UIButton *btnSelect=[[UIButton alloc]initWithFrame:CGRectMake(667, 7, 80, 30)];
    [btnSelect setTitle:@"筛选▲" forState:UIControlStateNormal];
    btnSelect.tag=10011;
//    ▲▼
    [btnSelect setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btnSelect.layer setBorderWidth:1];
    [btnSelect.layer setBorderColor:[UIColor lightGrayColor].CGColor];
    btnSelect.titleLabel.font=[UIFont systemFontOfSize:15];
    [btnSelect addTarget:self action:@selector(ShowOrHideDown:) forControlEvents:UIControlEventTouchUpInside];
    [vieHead addSubview:btnSelect];
    
    
    
    
    vieDown=[[UIView alloc]initWithFrame:CGRectMake(0, 44, self.frame.size.width, 300)];
     vieDown.frame=CGRectMake(0, -256, self.frame.size.width, 300);
    vieDown.backgroundColor=[UIColor clearColor];
//    vieDown.alpha=0.9;
    vieDown.hidden=YES;
    CGRect vieBackFrame=vieDown.bounds;
    vieBackFrame.size=CGSizeMake(vieBackFrame.size.width, vieBackFrame.size.height-5);

//    半透明
    UIView *vieBack=[[UIView alloc]initWithFrame:vieBackFrame];
    vieBack.backgroundColor=[UIColor whiteColor];
    vieBack.alpha=0.7;
    [vieDown addSubview:vieBack];
    
//    阴影
    UIImageView *imgBack=[[UIImageView alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(vieDown.bounds)-5, CGRectGetWidth(vieDown.bounds), 5)];
    imgBack.image=[UIImage imageNamed:@"downVieShow"];
    [vieDown addSubview:imgBack];
    [self insertSubview:vieDown belowSubview:vieHead];
    
//  分割线
    UILabel *lab=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), 1)];
    lab.backgroundColor=[UIColor lightGrayColor];
    [vieDown addSubview:lab];
//分类    
    for (int i=0; i<3; i++) {
        UIView *vieContent=[[UIView alloc]initWithFrame:CGRectMake(0+256*i, 1, 256, vieDown.frame.size.height-1)];
        [vieDown addSubview:vieContent];
        UILabel *labTitle=[[UILabel alloc]initWithFrame:CGRectMake(25, 15, 50, 26)];
        labTitle.text=@"颜色";
        labTitle.font=[UIFont boldSystemFontOfSize:17];
        [vieContent addSubview:labTitle];
        for (int j=0; j<3; j++) {
            UIButton *labSelect=[[UIButton alloc]initWithFrame:CGRectMake(25+j%2*80, 50+j/2*40, 65, 26)];
           
//            labSelect.textAlignment=NSTextAlignmentCenter;
            
            
            [labSelect addTarget:self  action:@selector(SelectClass:) forControlEvents:UIControlEventTouchUpInside];
//            labSelect.textColor=[UIColor whiteColor];
            labSelect.titleLabel.font=[UIFont boldSystemFontOfSize:13];
            [vieContent addSubview:labSelect];
            if (j==0) {
                labSelect.backgroundColor=[UIColor redColor];
                [labSelect setTitle:@"全部" forState:UIControlStateNormal];
                 [labSelect setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            }
            else{
               labSelect.backgroundColor=[UIColor whiteColor];
                [labSelect setTitle:[NSString stringWithFormat:@"系列%d",j] forState:UIControlStateNormal];
                 [labSelect setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                [labSelect.layer setBorderWidth:1];
                [labSelect.layer setBorderColor:[UIColor blackColor].CGColor];
            }
        }
    }
//    UILabel *labDown=[[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(vieDown.bounds)-1, CGRectGetWidth(self.bounds), 1)];
//    labDown.backgroundColor=[UIColor lightGrayColor];
//    
//    [vieDown addSubview:labDown];

}
-(void)SelectClass:(UIButton *)sender{
    for (id view in sender.superview.subviews) {
        if ([view isKindOfClass:[UIButton class]]) {
            UIButton *button=view;
            if (button==sender) {
                button.layer.borderColor=[[UIColor clearColor] CGColor];
                button.layer.borderWidth=1;
                button.backgroundColor=[UIColor redColor];
                [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
               
            }else{
                button.layer.borderColor=[[UIColor blackColor] CGColor];
                button.layer.borderWidth=1;
                 button.backgroundColor=[UIColor whiteColor];
                 [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            }
        }
    }
    [self HideVieDown];
    MainApp *app=[MainApp mainApp];
    [app.itemList removeAllObjects];
     [app.itemList addObjectsFromArray:[AppUI getAllSuit]];
    [[NSNotificationCenter defaultCenter] postNotificationName:ItemListNotification object:self];
   
}
-(void)HideVieDown{
    UIButton *btn=(UIButton *)[self viewWithTag:10011];
    [btn setTitle:@"筛选▲" forState:UIControlStateNormal];
    [self HideView];
 
}
-(void)ShowOrHideDown:(UIButton *)sender{
    if (vieDown.hidden) {
        vieDown.hidden=NO;
        [self ShowView];
        [sender setTitle:@"筛选▼" forState:UIControlStateNormal];
    }
    else{
        [self HideView];
        [sender setTitle:@"筛选▲" forState:UIControlStateNormal];
    }
}
-(void)ShowView{
    [UIView animateWithDuration:0.3 animations:^{
        vieDown.frame=CGRectMake(0, 44, self.frame.size.width, 300);
        self.frame=CGRectMake(0, 0, self.frame.size.width, 344);
    } completion:^(BOOL finished) {
        
    }];
}
-(void)HideView{
    [UIView animateWithDuration:0.3 animations:^{
        vieDown.frame=CGRectMake(0, -256, self.frame.size.width, 300);
         self.frame=CGRectMake(0, 0, self.frame.size.width, 44);
    } completion:^(BOOL finished) {
        vieDown.hidden=YES;
    }];
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
